package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

import org.come.Frame.MountJframe;
import org.come.Frame.MountSkillsJframe;
import org.come.entity.Mount;
import org.come.until.MessagrFlagUntil;
import org.come.until.Util;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * 坐骑技能窗口类
 * 
 * @author Administrator
 * 
 */

public class MountSkillsJpanel extends JPanel {

    private JList<String> listmountskill,// 坐骑技能列表
            listskilleffect;// 坐骑技能效果列表
    private DefaultListModel<String> modelmountskill,// 坐骑技能列表对象
            modelskilleffect;// 坐骑技能效果列表对象
    private JLabel labProficiency;// 熟练度

    public MountSkillsJpanel() throws Exception {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
    		this.setPreferredSize(new Dimension(318, 327));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 20);
            offBtn.setBounds(318 - 37, 10, 25, 25);
            this.add(offBtn);
            // 坐骑技能列表对象
            modelmountskill = new DefaultListModel<String>();
            // 坐骑技能列表
            listmountskill = new JList<String>() {
                {
                    setOpaque(false);
                } // instance initializer
            };
            listmountskill.setSelectionBackground(new Color(33, 42, 52));
            listmountskill.setSelectionForeground(Color.GREEN);
            listmountskill.setForeground(Color.GREEN);
            listmountskill.setFont(new Font("微软雅黑", 0, 13));
            listmountskill.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listmountskill.setModel(modelmountskill);
            listmountskill.addMouseListener(new MouseListener() {

                @Override
                public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mousePressed(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseExited(MouseEvent e) {
                    // TODO Auto-generated method stub
                    if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE12)) {
                        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                    }

                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    // TODO Auto-generated method stub
                    if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE1)) {
                        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                    }

                }

                @Override
                public void mouseClicked(MouseEvent e) {

                    // 判断是否有选中坐骑
                    if (MountJframe.getMountjframe().getMountjpanel().getListmount().getSelectedIndex() != -1) {

                        int index = MountJframe.getMountjframe().getMountjpanel().getListmount().getSelectedIndex();
                        Mount mount = ZhuJpanel.getListMount().get(index);

                        // 先判断这只召唤兽是否有技能
                        if (ZhuJpanel.getListMount().get(index).getMountskill().size() != 0) {

                            // 判断是否有选中技能
                            if (listmountskill.getSelectedIndex() != -1) {// 有

                                int n = listmountskill.getSelectedIndex();

                                if (Util.calculateAddition(mount, mount.getMountskill().get(n).getSkillname()) != null) {
                                    String[] mountaut = Util.calculateAddition(mount,
                                            mount.getMountskill().get(n).getSkillname()).split("\\|");

                                    modelskilleffect.removeAllElements();

                                    // 将技能属性一个个展示出来
                                    for (int i = 0; i < mountaut.length; i++) {

                                        modelskilleffect.add(i, Util.changeToPercentage(mountaut[i]));

                                    }
                                }

                            } else {// 没有，展示第一个技能的属性

                                if (Util.calculateAddition(mount, mount.getMountskill().get(0).getSkillname()) != null) {
                                    String[] mountaut = Util.calculateAddition(mount,
                                            mount.getMountskill().get(0).getSkillname()).split("\\|");

                                    modelskilleffect.removeAllElements();

                                    // 将技能属性一个个展示出来
                                    for (int i = 0; i < mountaut.length; i++) {

                                        modelskilleffect.add(i, Util.changeToPercentage(mountaut[i]));

                                    }
                                }

                            }

                        } else {// 没有，清空界面

                            MountSkillsJframe.getMountSkillsJframe().getMountSkillsJpanel().getModelmountskill()
                                    .removeAllElements();
                            // 清空坐骑技能面板
                            MountSkillsJframe.getMountSkillsJframe().getMountSkillsJpanel().getModelskilleffect()
                                    .removeAllElements();

                        }

                    }

                }
            });

            // 坐骑技能列表
            listmountskill.setBounds(49, 52, 247, 70);
            this.add(listmountskill);

            // 坐骑技能效果列表对象
            modelskilleffect = new DefaultListModel<String>();

            // 坐骑技能效果列表
            listskilleffect = new JList<String>() {
                {
                    setOpaque(false);
                } // instance initializer
            };
            listskilleffect.setSelectionBackground(new Color(33, 42, 52));
            listskilleffect.setSelectionForeground(Color.YELLOW);
            listskilleffect.setForeground(Color.YELLOW);
            listskilleffect.setFont(new Font("微软雅黑", 0, 13));
            listskilleffect.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listskilleffect.setModel(modelskilleffect);
            // 坐骑技能效果列表
            listskilleffect.setBounds(49, 124, 235, 183);
            this.add(listskilleffect);

            // 熟练度
            labProficiency = new JLabel();
            labProficiency.setBounds(104, 291, 188, 12);
            labProficiency.setForeground(Color.WHITE);
            labProficiency.setFont(new Font("微软雅黑", 0, 13));
            this.add(labProficiency);
        } else {
            //
            this.setPreferredSize(new Dimension(337, 357));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 20);
            offBtn.setBounds(317, 0, 23, 23);
            this.add(offBtn);
            // 坐骑技能列表对象
            modelmountskill = new DefaultListModel<String>();
            // 坐骑技能列表
            listmountskill = new JList<String>() {
                {
                    setOpaque(false);
                } // instance initializer
            };
            listmountskill.setSelectionBackground(new Color(33, 42, 52));
            listmountskill.setSelectionForeground(Color.GREEN);
            listmountskill.setForeground(Color.GREEN);
            listmountskill.setFont(new Font("微软雅黑", 0, 13));
            listmountskill.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listmountskill.setModel(modelmountskill);
            listmountskill.addMouseListener(new MouseListener() {

                @Override
                public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mousePressed(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseExited(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseClicked(MouseEvent e) {

                    // 判断是否有选中坐骑
                    if (MountJframe.getMountjframe().getMountjpanel().getListmount().getSelectedIndex() != -1) {

                        int index = MountJframe.getMountjframe().getMountjpanel().getListmount().getSelectedIndex();
                        Mount mount = ZhuJpanel.getListMount().get(index);

                        // 先判断这只召唤兽是否有技能
                        if (ZhuJpanel.getListMount().get(index).getMountskill().size() != 0) {

                            // 判断是否有选中技能
                            if (listmountskill.getSelectedIndex() != -1) {// 有

                                int n = listmountskill.getSelectedIndex();

                                if (Util.calculateAddition(mount, mount.getMountskill().get(n).getSkillname()) != null) {
                                    String[] mountaut = Util.calculateAddition(mount,
                                            mount.getMountskill().get(n).getSkillname()).split("\\|");

                                    modelskilleffect.removeAllElements();

                                    // 将技能属性一个个展示出来
                                    for (int i = 0; i < mountaut.length; i++) {

                                        modelskilleffect.add(i, Util.changeToPercentage(mountaut[i]));

                                    }
                                }

                            } else {// 没有，展示第一个技能的属性

                                if (Util.calculateAddition(mount, mount.getMountskill().get(0).getSkillname()) != null) {
                                    String[] mountaut = Util.calculateAddition(mount,
                                            mount.getMountskill().get(0).getSkillname()).split("\\|");

                                    modelskilleffect.removeAllElements();

                                    // 将技能属性一个个展示出来
                                    for (int i = 0; i < mountaut.length; i++) {

                                        modelskilleffect.add(i, Util.changeToPercentage(mountaut[i]));

                                    }
                                }

                            }

                        } else {// 没有，清空界面

                            MountSkillsJframe.getMountSkillsJframe().getMountSkillsJpanel().getModelmountskill()
                                    .removeAllElements();
                            // 清空坐骑技能面板
                            MountSkillsJframe.getMountSkillsJframe().getMountSkillsJpanel().getModelskilleffect()
                                    .removeAllElements();

                        }

                    }

                }
            });

            // 坐骑技能列表
            listmountskill.setBounds(40, 46, 247, 70);
            this.add(listmountskill);

            // 坐骑技能效果列表对象
            modelskilleffect = new DefaultListModel<String>();

            // 坐骑技能效果列表
            listskilleffect = new JList<String>() {
                {
                    setOpaque(false);
                } // instance initializer
            };
            listskilleffect.setSelectionBackground(new Color(33, 42, 52));
            listskilleffect.setSelectionForeground(Color.YELLOW);
            listskilleffect.setForeground(Color.YELLOW);
            listskilleffect.setFont(new Font("微软雅黑", 0, 13));
            listskilleffect.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listskilleffect.setModel(modelskilleffect);
            // 坐骑技能效果列表
            listskilleffect.setBounds(35, 129, 271, 183);
            this.add(listskilleffect);

            // 熟练度
            labProficiency = new JLabel();
            labProficiency.setBounds(146, 317, 130, 17);
            labProficiency.setForeground(Color.WHITE);
            labProficiency.setFont(new Font("微软雅黑", 0, 13));
            this.add(labProficiency);
        }
    }

    ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 召唤兽技能
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        	// 召唤兽技能
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B226.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 318, 327, this);
        } else {
            if (icon == null)
                icon = new ImageIcon("img/xy2uiimg/71_png.xy2uiimg.mountskill.png");
            g.drawImage(icon.getImage(), 0, 0, 337, 357, this);
        }
    }

    public JList<String> getListmountskill() {
        return listmountskill;
    }

    public void setListmountskill(JList<String> listmountskill) {
        this.listmountskill = listmountskill;
    }

    public JList<String> getListskilleffect() {
        return listskilleffect;
    }

    public void setListskilleffect(JList<String> listskilleffect) {
        this.listskilleffect = listskilleffect;
    }

    public DefaultListModel<String> getModelmountskill() {
        return modelmountskill;
    }

    public void setModelmountskill(DefaultListModel<String> modelmountskill) {
        this.modelmountskill = modelmountskill;
    }

    public DefaultListModel<String> getModelskilleffect() {
        return modelskilleffect;
    }

    public void setModelskilleffect(DefaultListModel<String> modelskilleffect) {
        this.modelskilleffect = modelskilleffect;
    }

    public JLabel getLabProficiency() {
        return labProficiency;
    }

    public void setLabProficiency(JLabel labProficiency) {
        this.labProficiency = labProficiency;
    }

}
